// pages/SCM/feedback/selectType/selectType.js
const app = getApp()
const util = require('../../../../utils/util.js')
const lbbService = require('../../../service/service.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    activeIndex:0,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      scrollHeight: app.getScrollHeight(0),
      hospitalId:options.hospitalId?options.hospitalId:'',
      hospitalName: options.hospitalName?options.hospitalName:''
    })
    this.getTypes();
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },
  /**
   * 选择一级分类
   */
  toggle: function(e) {
    let index = e.currentTarget.dataset.index;
    this.setData({
      activeIndex:index
    })
  },
  /**
   * 选择二级分类
   */
  toggleSecondTab: function(e) {
    let that = this;
    let index = e.currentTarget.dataset.index;
    let list = that.data.list;
    let activeIndex = that.data.activeIndex;
    let typeInfo = JSON.stringify({
      label:list[activeIndex].label,
      id:list[activeIndex].id,
      child:{
        label:list[activeIndex].list[index].label,
        id:list[activeIndex].list[index].id,
        isEquCode: list[activeIndex].list[index].isEquCode,
        isEquPart: list[activeIndex].list[index].isEquPart,
      }
    });
    let child = list[activeIndex].list[index];
    let partList = [];
    if(child.accId){
      partList = [{id:child.accId,accName:child.accName,maximumNum:child.maximumNum,accNum:1,label:child.label}]
    }
    wx.navigateTo({
      url: '../newProblem/newProblem?typeInfo=' + typeInfo+'&hospitalId='+that.data.hospitalId+'&hospitalName='+that.data.hospitalName+'&partList='+JSON.stringify(partList),
    })
  },
  /**
   * 获取分类
   */
  getTypes: function(){
    let that = this;
    lbbService.getFeedbackQuestionTypeInfo({},res=>{
      that.setData({
        list:res.data
      })
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})